#include <bits/stdc++.h>
using namespace std;

#define OK 1
#define ERROR 0
#define MAXSIZE 5

struct QElemType{
	int num;
};

typedef struct {
	QElemType* base;
	int front;
	int rear;
}SqQueue;

int InitQueue(SqQueue&Q){
	Q.base = new QElemType[MAXSIZE];
	if(!Q.base) exit(ERROR);
	Q.front = Q.rear = 0;
	return OK;
}

int Queuelength(SqQueue Q){
	return (Q.rear-Q.front+MAXSIZE) % MAXSIZE;
}

int push(SqQueue&Q,QElemType e){
	if((Q.rear+1)%MAXSIZE==Q.front) return ERROR;
	
	Q.base[Q.rear] = e; 
	Q.rear = (Q.rear+1) % MAXSIZE;
	return OK;
}

int pop(SqQueue&Q,QElemType&e){
	if(Q.front==Q.rear) return ERROR;
	e = Q.base[Q.front];
	Q.front = (Q.front+1) %MAXSIZE;
	return OK;
}

int main(){
	
	SqQueue Q;
	InitQueue(Q);
	for(int i = 1;i<=10;i++) push(Q,QElemType{i});
	QElemType e;
	while(pop(Q,e)) printf("%d ",e.num);
	
	return 0;
}
